#pragma once

#include <QWidget>

#include "widgets.h"

class S_WIDGETS_EXPORT SCheckEx : public QWidget {
  Q_OBJECT
 public:
  enum class SelectType { Check, Radio, Switch };

  SCheckEx(const QString&, QWidget* parent = nullptr);
  ~SCheckEx() = default;

  void setSelectType(SelectType v) { m_type = v; }
  void setIndex(int v) { m_index = v; }
  int index() const { return m_index; }
  bool isSelected() { return m_selectState != Qt::Unchecked; }
  void setSelectState(Qt::CheckState v, bool notify = false);
  void setTextBk(bool isSetBk = true) { m_bSetTextBK = isSetBk; }
  virtual QSize sizeHint() const override;

 Q_SIGNALS:
  void stateChanged(int);

 protected:
  virtual void mousePressEvent(QMouseEvent*) override;
  virtual void enterEvent(QEvent* event) override;
  virtual void leaveEvent(QEvent* event) override;
  virtual void paintEvent(QPaintEvent* event) override;

 private:
  SelectType m_type = SelectType::Check;
  QString m_text;
  int m_index = 0;
  Qt::CheckState m_selectState = Qt::Unchecked;
  bool m_hover = false;
  bool m_bSetTextBK = true;
};

class S_WIDGETS_EXPORT SRadioGroup : public QObject {
  Q_OBJECT
 public:
  SRadioGroup(QObject* p);
  SCheckEx* getSCheckEx(int index) const;
  void addRadio(SCheckEx*);
  int getSCheckExCount() const;
 protected Q_SLOTS:
  void onRadioSelect(int);

 private:
  std::map<int, SCheckEx*> m_items;
};